﻿Imports System.Data.SqlClient
Public Class Avocat_partenaire
    Public Id As Integer
    Public Num_Prof As String
    Public Nom As String
    Public Prenom As String
    Public Nom_a As String
    Public Prenom_a As String
    Public Ville As String
    Public Autorite As String
    Public Email As String
    Public Adress As String
    Public Remarque As String

    'Les constructeur -------------------------
    Sub New(ByVal Id As Integer, ByVal Num_Prof As String, ByVal Nom As String, ByVal Prenom As String, ByVal Nom_a As String, ByVal Prenom_a As String, ByVal Ville As String, ByVal Autorite As String, ByVal Email As String, ByVal Adress As String, ByVal Remarque As String)
        Me.Id = Id
        Me.Nom = Nom
        Me.Prenom = Prenom
        Me.Nom_a = Nom_a
        Me.Prenom_a = Prenom_a
        Me.Ville = Ville
        Me.Autorite = Autorite
        Me.Email = Email
        Me.Adress = Adress
        Me.Remarque = Remarque
        Me.Num_Prof = Num_Prof

    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Num_Prof = enregistrement.Item(1)
        Me.Nom_a = enregistrement.Item(2)
        Me.Prenom_a = enregistrement.Item(3)
        Me.Nom = enregistrement.Item(4)
        Me.Prenom = enregistrement.Item(5)
        Me.Ville = enregistrement.Item(6)
        Me.Autorite = enregistrement.Item(7)
        Me.Email = enregistrement.Item(9)
        Me.Adress = enregistrement.Item(8)
        Me.Remarque = enregistrement.Item(10)
    End Sub

    Sub New()

    End Sub

    'les listes ---------------------------------
    Public list_phone As New ArrayList

    'les fonctions ---------------------------

    Public Sub remplir_List_list_phone()
        Partager.close()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where id_Avocat_Partonaire=" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)
        Next
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where Type ='" & type & "' and Id_Avocat_Partonaire=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        'Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Avocat_Partonaire) values (@Num,@Type,@Id_Avocat_Partonaire)", Partager.con)

        cmd.Parameters.Add("@Id_Avocat_Partonaire", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub

End Class
